package com.dyh.service.serviceImpl;
/*引用userDao接口、user实体类、userService接口*/
import com.dyh.service.userService;
import com.dyh.dao.userDao;
import com.dyh.po.user;
/*引用springframework架构*/
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("userService")
@Transactional
/**
 * 实现userService中的方法
 * @see com.dyh.service.userService
 */
public class userServiceImpl implements userService {
    @Autowired
    private userDao userdao;

    /**
     * 通过用户名与密码实现登录
     * @param username
     * @param userpwd
     * @return user
     */
    @Override
    public user findUserByUserName(String username, String userpwd) {
        user loginUser = this.userdao.findUserByUserName(username,userpwd);
        return loginUser;
    }

    /**
     * 查找所有用户
     * @return List
     */
    @Override
    public List<user> findAllUser() {
        return userdao.findAllUser();
    }

    /**
     * 通过用户名查找用户
     * @param username
     * @return
     */
    @Override
    public user findUserById(String username) {
        return userdao.findUserById(username);
    }

    /**
     * 修改用户
     * @param username
     * @param pwd
     * @param fullname
     * @param email
     * @param telephone
     * @param roleid
     * @return int
     */
    @Override
    public int editUser(String username, String pwd, String fullname, String email, String telephone, Long roleid) {
        return userdao.editUser(username,pwd,fullname,email,telephone,roleid);
    }

    /**
     * 添加用户信息到用户表
     * @param username
     * @param pwd
     * @param fullname
     * @param email
     * @param telephone
     * @return int
     */
    @Override
    public int addIntoUser(String username, String pwd, String fullname, String email, String telephone) {
        return userdao.addIntoUser(username,pwd,fullname,email,telephone);
    }

    /**
     * 添加用户到用户角色关联表
     * @param username
     * @param roleid
     * @return int
     */
    @Override
    public int addIntoUserRole(String username,Long roleid) {
        return userdao.addIntoUserRole(username,roleid);
    }

    /**
     * 删除用户信息
     * @param username
     * @return int
     */
    @Override
    public int deleteUser(String username) {
        return userdao.deleteUser(username);
    }
}
